using System;
using System.Collections.Generic;
using System.Text;
using System.Threading;
using Microsoft.Practices.RepositoryFactory.CodeGeneration.ObjectModel.Mappings;
using Microsoft.Practices.RepositoryFactory.CodeGeneration.ObjectModel.NamingConventions;
using System.Data;

namespace Microsoft.Practices.RepositoryFactory.CodeGeneration.ObjectModel
{
    public static class EntityHelper
    {
        /// <summary>
        /// Builds a string using the entity primary keys info, 
        /// to be used on the DebuggerDisplay attribute of the entity class.
        /// </summary>
        /// <param name="entity">Entity which DebuggerDisplay info we need.</param>
        /// <returns>String for the DebuggerDisplay attribute.</returns>
        public static string GetDebuggerDisplay(Entity entity)
        {
            if (entity == null) throw new ArgumentNullException();

            string response = "";

            foreach (Property property in entity.Properties)
            {
                if (property.IsPrimaryKey)
                {
                    if (response.Length > 0)
                        response += ", ";

                    response += property.Name + " = {" + property.Name + "}";
                }
            }

            return response;
        }

        /// <summary>
        /// Determine the total number of primary keys.
        /// </summary>
        /// <param name="entity"></param>
        /// <returns>Total number of primary keys.</returns>
        public static int TotalPrimaryKeys(Entity entity)
        {
            if (entity == null) throw new ArgumentNullException();

            int total = 0;

            foreach (Property property in entity.Properties)
            {
                if (property.IsPrimaryKey)
                {
                    total++;
                }
            }

            return total;
        }
    }
}
